#include <iostream>
#include <vector>

using namespace std;

class Solution 
{
public:
    int removeElement(vector<int>& nums, int val) 
    {
        int slow = 0; 
        int fast = 0;
        for(; fast < nums.size(); fast++)
        {
            if(nums[fast] != val)
            {
                nums[slow] = nums[fast];
                slow++;
            }
        }
        return slow;
    }
};

int main()
{
    Solution s;

    // 测试用例1
    vector<int> nums1 = {3,2,2,3};
    int val1 = 3;
    int len1 = s.removeElement(nums1, val1);
    cout << "测试1: 新长度 = " << len1 << "，新数组 = [";
    for(int i = 0; i < len1; i++) {
        cout << nums1[i];
        if(i != len1 - 1) cout << ",";
    }
    cout << "] (期望: 2, [2,2])" << endl;

    // 测试用例2
    vector<int> nums2 = {0,1,2,2,3,0,4,2};
    int val2 = 2;
    int len2 = s.removeElement(nums2, val2);
    cout << "测试2: 新长度 = " << len2 << "，新数组 = [";
    for(int i = 0; i < len2; i++) {
        cout << nums2[i];
        if(i != len2 - 1) cout << ",";
    }
    cout << "] (期望: 5, [0,1,3,0,4])" << endl;

    // 测试用例3
    vector<int> nums3 = {1,1,1,1};
    int val3 = 1;
    int len3 = s.removeElement(nums3, val3);
    cout << "测试3: 新长度 = " << len3 << "，新数组 = [";
    for(int i = 0; i < len3; i++) {
        cout << nums3[i];
        if(i != len3 - 1) cout << ",";
    }
    cout << "] (期望: 0, [])" << endl;

    // 测试用例4
    vector<int> nums4 = {4,5};
    int val4 = 3;
    int len4 = s.removeElement(nums4, val4);
    cout << "测试4: 新长度 = " << len4 << "，新数组 = [";
    for(int i = 0; i < len4; i++) {
        cout << nums4[i];
        if(i != len4 - 1) cout << ",";
    }
    cout << "] (期望: 2, [4,5])" << endl;

    return 0;
}
